<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>微信登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/login.css">
    <script src="/js/plugins/qrcode/qrcode.min.js"></script>
    <script>

    </script>

</head>
<body>
<!--<input id="text" type="text" value="https://013f5d49.ngrok.io/loginByWeiXin" hidden/><br />-->
<input id="uuid" type="hidden"/>
<div class="container">
    <h5>微信扫码登录</h5>

    <div class="card card-container " id="qrcode">

    </div>


    <a href="login.html" class="registerLink">
        返回登录页面
    </a>
</div>
<script type="text/javascript">
    var qrcode = new QRCode(document.getElementById("qrcode"), {
        width : 150,
        height : 150
    });

    function makeCode () {
        $.ajax({
            url:"/qrcode/showQrcode",
            async: false,
            success:function (data) {
                var result = data.result;
                $("#uuid").val(result.uuid);
                console.log(result.qrurl);
                qrcode.makeCode(result.qrurl);
            }
        });
    }

    //页面轮询检测二维码是否被扫描
    function checkScan() {
        var uuid=$("#uuid").val();
        setInterval(function() {
            $.get("/qrcode/checkScan?uuid=" + uuid,
                function(data) {
                    if (data.result!=null&&data.result.uuid!=null) {
                        sessionStorage.setItem('user',JSON.stringify(data.result.user));
                        //验证成功并重定向到welcome页面
                        window.parent.location.href = "index.html";
                    }

                });
        },4000)
    }

    $(function () {
       //初始化二维码
        makeCode();
        checkScan();

    })
</script>
</body>
</html>
